﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ApplyPathTemplateAction.CApApplyPathTemplateActionEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ApplyPathTemplateAction;

public class CApApplyPathTemplateActionEnabler : ITxCommandEnabler
{
  public bool Enable => this.ShouldEnable();

  private bool ShouldEnable()
  {
    bool flag = false;
    if (!TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      flag = false;
    else if (TxApplication.ActiveSelection.Count == 0)
    {
      flag = true;
    }
    else
    {
      TxObjectList filteredOperationsList = this.GetFilteredOperationsList();
      if (TxApplication.ActiveSelection.Count == ((Collection<ITxObject>) filteredOperationsList).Count)
      {
        CApApplyPathTemplateUtil pathTemplateUtil = new CApApplyPathTemplateUtil();
        TxRobot robot = pathTemplateUtil.GetRobot(((Collection<ITxObject>) filteredOperationsList)[0] as ITxOperation);
        if (TxRobot.op_Inequality(robot, (ITxObject) null))
        {
          flag = true;
          for (int index = 0; index < ((Collection<ITxObject>) filteredOperationsList).Count & flag; ++index)
            flag = TxRobot.op_Equality(pathTemplateUtil.GetRobot(((Collection<ITxObject>) filteredOperationsList)[index] as ITxOperation), (ITxObject) robot) && ((Collection<ITxObject>) filteredOperationsList)[index].CanBeModified;
        }
      }
      if (!flag && ((Collection<ITxObject>) TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) new TxTypeFilter(typeof (TxRobot)))).Count == 1)
        flag = true;
    }
    return flag;
  }

  private TxObjectList GetFilteredOperationsList()
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (ITxWeldOperation));
    txTypeFilter.AddIncludedType(typeof (TxGenericRoboticOperation));
    txTypeFilter.AddIncludedType(typeof (ITxContinuousOperation));
    txTypeFilter.AddIncludedType(typeof (TxRoboticSeamOperation));
    txTypeFilter.AddIncludedType(typeof (TxCompoundOperation));
    return TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter);
  }
}
